package kz.alamty.dev.dao;

import static org.junit.Assert.*;
import kz.alamty.dev.obj.Answer;
import kz.alamty.dev.obj.Question;
import kz.alamty.dev.obj.User;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.junit.Before;
import org.junit.Test;

public class AnswerDAOTest {
	private kz.alamty.dev.obj.Answer answer;
	private Question question;
	private User user;
	private AnswerDAO asdao;
	private QuestionDAO qdao;
	@Before
	public void setUp() throws Exception {
		asdao = new AnswerDAO();
		qdao = new QuestionDAO();
		user = new User("me", "123456");
		question = new Question(user,"Green is yours like Color?");
		answer = new Answer(question, user, "0");
		
	}

	@Test
	public void testSave() {
		Session session = this.asdao.getSession();
		Transaction trans = null;
        try {
			trans = session.beginTransaction();
			session.save(user);	
			session.save(question);
			session.save(answer);
			trans.commit();
		} catch (HibernateException e) {
			// TODO Auto-generated catch block
			trans.rollback();
			e.printStackTrace();
			fail("Not yet implemented");
			assertTrue(false);
		}finally{
			session.close();
		}
		
		
	}

	@Test
	public void testDelete() {
		asdao.delete(answer);
		
	}

}
